/**
 * Copyright 2010 Pavel Daniel Alexandru PFA
 * 
 * Licensed under the terms of the GNU Lesser General Public License version 3 
 * as published by the Free Software Foundation. You may obtain a copy of the
 * License at: http://www.gnu.org/copyleft/lesser.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations 
 * under the License. 
 */
package com.kobol.webclient.client.signin.view;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.ViewWithUiHandlers;
import com.kobol.webclient.client.signin.presenter.SignInPagePresenter;

/**
 * @author Pavel Alexandru
 * 
 */
public class SignInPageView extends ViewWithUiHandlers<SignInPageUIHandlers> implements SignInPagePresenter.MyView {

    private static String html = "<div>\n" + "<table align=\"center\">\n" + "  <tr>\n" + "<td>&nbsp;</td>\n"
	    + "<td>&nbsp;</td>\n" + "</tr>\n" + "  <tr>\n" + "<td>&nbsp;</td>\n" + "<td>&nbsp;</td>\n" + "</tr>\n"
	    + "  <tr>\n" + "<td>&nbsp;</td>\n" + "<td>&nbsp;</td>\n" + "</tr>\n" + "  <tr>\n"
	    + "    <td colspan=\"2\" style=\"font-weight:bold;\">Sign In <img src=\"images/signin.gif\"/></td>\n"
	    + "  </tr>\n" + "  <tr>\n" + "    <td>User name</td>\n" + "    <td id=\"userNameFieldContainer\"></td>\n"
	    + "  </tr>\n" + "  <tr>\n" + "    <td>Password</td>\n" + "    <td id=\"passwordFieldContainer\"></td>\n"
	    + "  </tr>\n" + "  <tr>\n" + "    <td></td>\n" + "    <td id=\"signInButtonContainer\"></td>\n"
	    + "  </tr>\n" + "  <tr>\n" + "<td>&nbsp;</td>\n" + "<td>&nbsp;</td>\n" + "</tr>\n" + "  <tr>\n"
	    + "    <td colspan=\"2\">Forget your password?</td>\n" + "  </tr>\n" + "  <tr>\n"
	    + "    <td colspan=\"2\">Contact your Kobol Webclient administrator.</td>\n" + "  </tr>\n" + "</table>\n"
	    + "</div>\n";

    HTMLPanel panel = new HTMLPanel(html);

    private final TextBox userNameField;
    private final PasswordTextBox passwordField;
    private final Button signInButton;

    @Inject
    public SignInPageView() {
	userNameField = new TextBox();
	passwordField = new PasswordTextBox();
	signInButton = new Button("Sign in");

	userNameField.setText("administrator");
	passwordField.setText("1234567890");

	panel.add(userNameField, "userNameFieldContainer");
	panel.add(passwordField, "passwordFieldContainer");
	panel.add(signInButton, "signInButtonContainer");
    }

    @Override
    public Widget asWidget() {
	return panel;
    }

    @Override
    public String getUserName() {
	return userNameField.getText();
    }

    @Override
    public String getPassword() {
	return passwordField.getText();
    }

    @Override
    public Button getSignInButton() {
	return signInButton;
    }

    @Override
    public void resetAndFocus() {
	userNameField.setFocus(true);
	userNameField.selectAll();
    }
}